package com.hotel.project.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisConfig{
    private String host = "127.0.0.1";
    private int port = 6379;
    private String password;
    private String timeout = "5000ms";
    private int maxActive = 1024;
    private String maxWait = "5000ms";
    private int maxIdle = 200;
    private int minIdle = 5;

    @Bean
    public JedisPool getJedisPool(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        //最大连接数
        jedisPoolConfig.setMaxTotal(maxActive);
        //最大连接阻塞时间
        jedisPoolConfig.setMaxWaitMillis(Long.valueOf(maxWait.substring(0,maxWait.length() - 2)));
        //最大空闲连接数
        jedisPoolConfig.setMaxIdle(maxIdle);
        //最小空闲连接数
        jedisPoolConfig.setMinIdle(minIdle);

        int to = Integer.valueOf(timeout.substring(0,timeout.length() - 2));
        JedisPool jPool = new JedisPool(jedisPoolConfig,host,port,to,password);
        return jPool;
    }
}
